#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>

int main()
{
    printf("Using execle!\n");
    pid_t id=fork();
    if(id<0)
    {
        perror("fork");
        return -1;
    }
    else if(id==0)
    {
        printf("I am child process!My pid::%d\n",getpid());
        extern char** environ;
        putenv((char*)"my_env=lrk_env");
        execle("./test","./test",NULL,environ);
    }
    else{
        printf("I am parent process!My pid::%d\n",getpid());
        sleep(2);
        int status=0;
        pid_t ret=waitpid(id,&status,0);
        if(ret<0)
        {
            printf("Waiting failed!\n");
        }
        else{
            printf("Waiting success!exit_result::%d,exit_code::%d,exit_signal::%d\n",ret,(status>>8)&0xFF,status&0x7F);
        }
    }
    return 0;
}
